package com.softer.wxzj.common.entity;

import com.softer.wxzj.common.enums.MessageEnum;
import com.softer.wxzj.common.enums.ShiroResultEnum;
import com.softer.wxzj.common.util.StringUtils;
import lombok.Data;

/**
 * @author zcz
 * @date 2019/1/16
 */
@Data
public class CommonResult {
    /**
     * id
     */
    private String id;
    /**
     * 登录账号
     */
    private String operNo;
    /**
     * 状态码
     */
    private Integer data;
    /**
     * 物业企业银行账户ID
     * （用于拨款账户管理模块中的企业新增）
     */
    private String orgBankId;
    /**
     * 状态信息
     */
    private String message;

    public CommonResult() {
    }

    public CommonResult(Integer data, String message) {
        this.data = data;
        this.message = message;
    }

    public CommonResult(Integer data, String message, String id) {
        this.data = data;
        this.message = message;
        this.id = id;
    }

    public CommonResult(Integer data, String message, String id, String operNo) {
        this.data = data;
        this.message = message;
        this.id = id;
        this.operNo = operNo;
    }

    /**
     * CURD操作时使用，返回是否操作成功
     *
     * @param i
     * @return
     */
    public static CommonResult ResponseResult(int i) {
        if (i > 0) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), MessageEnum.SUCCESS.getMsg());
        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
    }

    /**
     * CURD操作时使用，返回是否操作成功
     *
     * @param i
     * @return
     */
    public static CommonResult ResponseResult(int i, String str) {
        if (i > 0) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), str);
        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), str);
    }

    /**
     * 根据返回的字符串判断是否操作成功，返回是否操作成功
     *
     * @param str
     * @return
     */
    public static CommonResult ResponseResult(String str) {
        if (StringUtils.isNotBlank(str)) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), MessageEnum.SUCCESS.getMsg());
        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
    }

    /**
     * CURD操作时使用，返回是否操作成功,带id
     *
     * @param num
     * @param id
     * @return
     */
    public static CommonResult idResult(int num, String id) {
        if (num > 0) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), MessageEnum.SUCCESS.getMsg(), id);

        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
    }

    public static CommonResult idResult(int num, String id, String opeNo) {
        if (num > 0) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), MessageEnum.SUCCESS.getMsg(), id, opeNo);

        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), MessageEnum.FAIL.getMsg());
    }

    /**
     * CURD操作时使用，返回自定义字符串
     *
     * @param num
     * @param Str
     * @return
     */
    public static CommonResult strResult(int num, String Str) {
        if (num > 0) {
            return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), Str);
        }
        return new CommonResult(ShiroResultEnum.FAIL.getCode(), Str);
    }

    /**
     * CURD操作时使用，返回自定义字符串
     *
     * @param Str
     * @return
     */
    public static CommonResult strResult(String Str) {
        return new CommonResult(ShiroResultEnum.SUCCESS.getCode(), Str);
    }
}
